<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>实验室信息管理系统</title>
</head>
<body>
<script src="/static/qywx/js/vue.min.js"></script>
<script src="/static/qywx/js/jquery-1.12.4.min.js"></script>
    <div>
    </div>

<script>
    new Vue({
        el: '#intro',
        props: {
        },
        data() {
            return {
            }
        },
        computed: {
        },
        mounted() {
            this.login(this.getQueryVariable().code);
        },
        methods: {
            login(code) {
                if (!code) {
                    this.sendError('授权失败');
                    return;
                }
                // 登录
                var _this = this;
               $.ajax({
                    url: '/qywx/scan?code='+code,
                    contentType: 'application/json;charset=UTF-8',
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == '2') {
                            window.location.href = data.loginSuccessUrl;
                        } else {
                            _this.sendError('登录失败');
                        }
                    },
                    error : function () {
                        _this.sendError('登录失败');
                    }
                })
            },
            getQueryVariable() {
                let query = window.location.search.substring(1);
                let vars = query.split("&");
                let param = {};
                for (let i=0;i<vars.length;i++) {
                    let pair = vars[i].split("=");
                    param[pair[0]] = pair[1];
                }
                return param;
            },
            sendError(msg) {
                window.sessionStorage.setItem('codeLoginMsg', msg);
                window.sessionStorage.setItem('changeEntryState','code');
                window.location.href="javascript:history.go(-1)";
            }
        },
    });
</script>
</body>
</html>